<template>
  <el-dialog title="编辑校区" :visible.sync="dialogVisible" width="1000px" :close-on-click-modal="false"
    :modal-append-to-body="false" v-drag2anywhere>
    <el-form :model="formData" ref="formData" label-width="85px" size="mini">
       <el-row :gutter="30">
         <el-col :span="8">
           <el-form-item label="校区名称" prop="title">
             <el-input v-model="formData.title" placeholder="校区名称"></el-input>
           </el-form-item>
         </el-col>

         <el-col  :span="8">
           <el-form-item label="负责人:" prop="manager">
             <el-input v-model="formData.manager" placeholder="负责人"></el-input>
           </el-form-item>
         </el-col>
         <el-col  :span="8">
           <el-form-item label="联系电话:" prop="manager">
             <el-input v-model="formData.mobile" placeholder="联系电话"></el-input>
           </el-form-item>
         </el-col>
         <el-col  >
           <el-form-item label="校区地址:" prop="manager">
             <el-input v-model="formData.address" placeholder="校区地址"></el-input>
           </el-form-item>
         </el-col>
         <el-col >
           <el-form-item label="校区简介:" prop="desc">
             <el-input type="textarea" v-model="formData.desc" placeholder="校区简介" :rows="5" maxlength="500" show-word-limit></el-input>
           </el-form-item>
         </el-col>
       </el-row>
     </el-form>
    <div slot="footer">
      <el-button @click="dialogVisible=false">取消</el-button>
       <el-button type="primary" @click="handleSave">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default{
    data(){
      return {
        index:-1,
        formData:{
          title:'',
          desc:'',
        },
        dialogVisible:false,
        rules:{
          title:[{required:true,message:"请正确填写校区名称",trigger:'blur'}]
        }
      }
    },
    methods:{
      initData(index,data){
          this.index=index;
          this.formData=data;
      },
      handleSave(){
          this.$refs.formData.validate(ok=>{
            const params = {
              id:this.formData.id,
              title: this.formData.title,
              desc: this.formData.desc,
              mobile: this.formData.mobile,
              manager: this.formData.manager,
              address: this.formData.address
            }
            this.api_helper.post("api/institution/area/update", params).then(res => {
              if (res.status == 200 && res.data.code == 1) {
                this.$message.success({
                  message: res.data.msg,
                  duration: 1500,
                  showClose: true
                });
                this.dialogVisible = false;
                this.$emit("complete",this.index,params);
              } else {
                this.$message.error({
                  message: res.data.msg,
                  duration: 1500,
                  showClose: true
                });
              }
            })


          });

      }
    }
  }
</script>

<style>
</style>
